<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		<meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1, maximum-scale=1, user-scalable=no">

		<link type="text/css" rel="stylesheet" href="__TMPL__/public/user/return/css/base.css" />
		<link type="text/css" rel="stylesheet" href="__TMPL__/public/user/return/css/sub.css" />
		<link type="text/css" rel="stylesheet" href="__TMPL__/public/user/return/css/module.css"  />
		<script type="text/javascript" src="__TMPL__/public/assets/js/jquery.min.js"></script>
		<script type="text/javascript" src="__TMPL__/public/assets/js/layer/layer.js"></script>
		<script type="text/javascript" src="/themes/Sbodycarving/public/assets/js/lrz.all.bundle.js"></script>
		<title>退换货</title>
	</head>
	<body>
		<div class="header"  style="border-bottom: 1px solid #d7d7d75e;">
		<h1>退换货</h1>
          
		<a href="javascript:history.back(-1);" class="back"><span></span></a>
		<a href="javascript:;" class=""></a>
</div>
<div class="shopping">
		<div class="shop">
			<foreach name="orders_info['order_goods']" item="vo">
				<php>$photo=json_decode($vo['goods_picture'],true);</php>
			<div class="pic1">
				<img src="{:cmf_get_image_preview_url($photo.thumbnail)}"/>
				<p><span>{$vo.goods_name}</span></p>
				<p><span>×{$vo.num}</span></p>
			</div>
			</foreach>
			<div class="rtdetail">
				<div><span>类型</span><span class="change"data="2">换货</span><span class="change" data="1">退货退款</span></div>
				<div><span>总价</span><span style="float:  right;padding-right: 15px;">￥{$orders_info.pay_money}+{$orders_info.pay_point}积分</span></div>
				<div><span>申请退款现金</span><span style="float:  right;padding-right: 15px;"><input type="number" max="{$orders_info.pay_money}" min="0" placeholder="0" class="return_price"></span></div>
				<div><span>申请退款积分</span><span style="float:  right;padding-right: 15px;"><input type="number" max="{$orders_info.pay_point}" min="0"  placeholder="0" class="return_socre"></span></div>
				<div><span>退换原因</span></div>
				<div class="rtpic" style=" position: relative;">
					<textarea class="txt"  name="" rows="5"  class="text" cols="" placeholder="请说明您购买商品遇到的问题，便于审核人员快速了解问题" maxlength="140"></textarea>
					<a href="javascript:;"><img src="__TMPL__/public/user/return/img/ph.png"/></a>
					<input type="file" accept="image/*" name="logo" id="upload_pic" style="position: absolute;left: 16px;opacity: 0;height: 67px;width: 67px;bottom: 71px;">
                    <div class="imgs" style="height: 65px;border:  none;"></div>
					<p>图片作为审核依据，请保持清晰，最多3张,如果换货时，退款金额请填0<span class="number"><span class="num">1</span>/140</span></p>
				</div>
			</div>
		</div>
		<div class="next">
			提交
		</div>
</div>
		<input type="hidden" name="return_type" value="1" class="return_type">
        <input type="hidden" name="img[]"  class="img_src">
        <input type="hidden" name="img[]"  class="img_src">
        <input type="hidden" name="img[]" class="img_src">

	<script type="text/javascript">
		$(function () {

            $(".change").click(function(){
                $(".change").css("color","#23262f");
                $(".change").css("background-color","#d7d7d7");
                $(this).css("color","#ddc38a");
                $(this).css("background-color","#23262f");
               var data=$(this).attr('data');
               $('.return_type').val(data)

            });

            $(".txt").keyup(function(){
                var len = $(".txt").val().length;
                $(".num").html(len);
            });

            $(".rtdetail input").keyup(function(){
                var v=$(this).val();
				var max=$(this).attr('max')
				var min=$(this).attr('min')
				if(max<v){
				    $(this).val(max)
				}
                if(min>v){
                    $(this).val(min)
                }
            });

            $("#upload_pic").change(function () {
                var flag=false;
                $(".img_src").each(function(i){
                    var v=$(this).val();
                    if(v==''){
                        flag=true;
                    }
                });
                if(flag){
                    /* 压缩图片 */
                    lrz(this.files[0], {
                        width: 700
                    }).then(function (rst) {
                        /* 处理成功后执行 */
                        rst.formData.append('base64img', rst.base64); // 添加额外参数
                        $.ajax({
                            url: "/user/profile/avatarupload.html",
                            type: "POST",
                            data: rst.formData,
                            processData: false,
                            contentType: false,
                            success: function (data) {
                                var data=eval('(' + data + ')')
                                var src  = "/upload/" + data.data.file;
                                if (data.code == 1) {
                                    $(".img_src").each(function(i){
                                        var v=$(this).val();
                                        if(v==''){
                                            $(this).val(src);
                                            $('.imgs').append('<img src="'+src+'" class="img_son">')
                                            return false;
                                        }
                                    });

                                }
                            }
                        });
                    }).catch(function (err) {
                        /* 处理失败后执行 */
                    }).always(function () {
                        /* 必然执行 */
                    })
                }else{
                    layer.msg('最多上传3张图片')
                }

            })


            $('body').on("click",".img_son",function(){
                var src=$(this).attr("src")
                $(this).remove();
                $(".img_src").each(function(i){
                    var v=$(this).val();
                    if(v==src){
                        $(this).val('');
                    }
                });
            });

            $('.next').click(function () {
              var order_id="{$orders_info['order_id']}";
              var return_price=$('.return_price').val();
              var return_socre=$('.return_socre').val();
              var return_type=$('.return_type').val();
              var text=$('.txt').val();
                if(return_type==2){
                    return_price=0;
                    return_socre=0;
                }
              if(order_id==''||return_type==''){
                  layer.msg('参数错误，请联系网站管理员');
                  return;
              }
                if(return_price==''&&return_type==1){
                    layer.msg('请填写退款现金金额');
                  console.log(return_price);
                    return;
                }
                if(return_socre==''&&return_type==1){
                    layer.msg('请填写退款积分');
                    return;
                }
                if(text==''){
                    layer.msg('请填写退款原因');
                    return;
                }

              var img_src = [];
                var imgs = $('.img_src');
                for (var i = 0; i < imgs.length; i++) {
                    img_src.push(imgs.eq(i).val());
                }
                $.ajax({
                    type: "POST",
                    url: '/user/order/return_order',
                    data: {
                        order_id:order_id,
                        return_price:return_price,
                        return_socre:return_socre,
                        return_type:return_type,
                        text:text,
                        img_src:img_src,
                    },
                    dataType: "json",
                    success: function (data) {
                        layer.msg(data.msg)
                        setTimeout('window.location.reload()',1000)
                    }
                });

            })
        })

	</script>
	</body>
</html>
